package com.china08.yxyapi.api.manage.sch.platform.resource.yxylectureprepack;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lecture.YxyLectureFeedBack;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyLectureFeedBackRepository;
import com.china08.yxyapi.util.DateToolUtils;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class YxyLectureSchPrePackFeedBackDetailController extends YxyApiBaseController {

    Logger log = Logger.getLogger(YxyLectureSchPrePackStatusController.class);

    @Autowired
    YxyLectureFeedBackRepository yxyLectureFeedBackRepository;

    @ApiOperation(value = "备课包详情")
    @RequestMapping(value = "/api_yw/manage/sch/platform/resource/lectureprepack/feedback/detial", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String prepackId = reqModel.prepackId;

        List<YxyLectureFeedBack> list = yxyLectureFeedBackRepository.findByPrepackIdOrderByCreatedDateDesc(prepackId);

        List<RespModel> returnList = new ArrayList<RespModel>();
        for (YxyLectureFeedBack yxyLectureFeedBack : list) {
            String userNick = yxyLectureFeedBack.getUserNick();
            String reason = yxyLectureFeedBack.getReason();
            String description = yxyLectureFeedBack.getDescription();
            Date CreatedDate = yxyLectureFeedBack.getCreatedDate();
            String date = "";
            if (CreatedDate != null) {
                date = DateToolUtils.format(CreatedDate, "yyyy-MM-dd");
            }
            RespModel respModel = new RespModel();
            respModel.userNick = userNick;
            respModel.reason = reason;
            respModel.description = description;
            respModel.date = date;
            returnList.add(respModel);
        }
        return returnList;
    }

    protected static class ReqModel extends YxyApiPageReqModel {
        public String prepackId;

        @Override
        public void autoCheck() {
            Assert.isTrue(StringUtils.isNotBlank(prepackId), "备课包为空");
        }
    }

    protected static class RespModel extends YxyApiRespModel {
        public String userNick;
        public String reason;
        public String description;
        public String date;
    }
}
